package com.wing.cabinet.model.entity;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import com.wing.product.model.entity.ProductDetail;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 售刀柜上货(上货主表无展示)/领取
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("cab_cell_inventory_inout")
public class CellInventoryInout extends BaseEntity<CellInventoryInout> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Type implements IEnum<Integer> {

        /**
        * 上货
        */
        in(1,"上货"),
        /**
        * 领取
        */
        out(2,"领取"),

        unload(3,"下货"),

        outByCabSpace(4,"领取(存刀柜)");

        private int code;
        private String desc;

        Type(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }


    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 存刀任务编号
     */
    private String code;

    /**
     * 配送单id
     */
    private Long deliveryId;

    /**
     * 操作类型
     */
    private Type type;

    /**
    * 操作类型描述
    */
    @TableField(exist = false)
    private String typeDesc;

    public String getTypeDesc() {
        return type == null ? null : type.getDesc();
    }

    /**
     * 状态:
     */
    private Integer status;

    /**
     * no
     */
    private Integer no;

    /**
     * day
     */
    private Integer day;

    /**
     * 是否同步成功
     */
    private Integer isSyns;

    @TableField(exist = false)
    private String uniqCode;


    private String deviceCode;

/*是否形成账单*/
    public enum IsBill implements IEnum<Integer> {

        /**
         * 未形成
         */
        no(0,"未形成"),
        /**
         * 领取
         */
        yes(1,"已形成");

        private int code;
        private String desc;

        IsBill(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }
    /**
     * 是否形成
     */
    private IsBill isBill;
    /**
     * 是否形成账单描述
     */
    @TableField(exist = false)
    private String isBillDesc;

    public String getIsBillDesc() {
        return isBill == null ? null : isBill.getDesc();
    }


    private Long receiveLoadId;

    private Long companyId;

    private String orderCode;

    @TableField(exist = false)
    private List<String> labelCodeList;

    /**
     * 企业编码
     */
    private String enterpriseCode;

    public enum BusinessType implements IEnum<Integer> {

        /**
         * 暂存
         */
        inByLoad(1,"上货"),
        cellCabOut(2,"售刀柜领新"),

        outByUnload(3,"下货"),

        cellCabOutByOldNew(4,"售刀柜领新(以旧换新)"),

        outByCabSpace(5,"存刀柜领新");

        private int code;
        private String desc;

        BusinessType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static BusinessType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (BusinessType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    private BusinessType businessType;


    private Long workOrderId;


    private Long departmentId;

    private String departmentName;

    /**
     * 同步时间
     */
    @JsonFormat(timezone = "GMT+8" , pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime synsTime;

    private BigDecimal total;

    private Long processId;

    @TableField(exist = false)
    private Integer remainingTime;

    @TableField(exist = false)
    private Integer settingTime;

    @TableField(exist = false)
    private ProductDetail.LifeUnit lifeUnit;

    @TableField(exist = false)
    private String lifeUnitDesc;

    public String getLifeUnitDesc(){
        if (this.lifeUnit!=null){
            return this.lifeUnit.getDesc();
        }else{
            return "";
        }
    }

    private String roleName;


    private Long storageInventoryInoutId;
    /**
     * 渠道编号
     */
    private String channelCode;


    private Long roleId;
    private String costCenter;

    /**
     * uuid 字段
     */
    private String uuid;

    /**
     * 主柜编号
     */
    private String mainCabCode;
}
